import 'package:dio/dio.dart';
import 'package:f_demo_two/components/shop_list.dart';
import 'package:flutter/material.dart';

class MyApp21 extends StatefulWidget {
  const MyApp21({super.key});

  @override
  State<MyApp21> createState() => _MyApp21State();
}

class _MyApp21State extends State<MyApp21> {
  List goodsLsit = [];

  @override
  void initState() {
    super.initState();
    getData();
  }

  void getData() async {
    Dio dio = Dio();
    final res = await dio.get('https://mock.boxuegu.com/mock/1172/orders');
    setState(() {
      goodsLsit = res.data;
      // print(goodsLsit);
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        //导航条
        appBar: AppBar(
          title: const Text('dio使用',
              style: TextStyle(
                  fontSize: 20,
                  fontWeight: FontWeight.bold,
                  color: Colors.white)),
          backgroundColor: Colors.pink,
          centerTitle: true,
        ),
        //主体区域
        body: ListView.separated(
          //列表的每一项
          itemBuilder: (BuildContext context, int index) {
            return ShopList(
              goods: goodsLsit[index],
            );
          },
          //分割线
          separatorBuilder: (BuildContext context, int index) {
            return Container(
              // height: 1,
              //color: Colors.black,
              margin: EdgeInsets.only(left: 10, right: 10),
              child: const Divider(
                height: 1,
                color: Colors.orange,
              ),
            );
          },
          //列表的长度
          itemCount: goodsLsit.length,
        ));
  }
}
